﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Moonlite.ExtensionApi.ControlInterfaces
{
    public abstract class AbstractCustomFolderNode : AbstractCustomNode
    {
        private Image openImage;
        private Image closedImage;
        public Image OpenImage
        {
            get
            {
                return openImage;
            }
            set
            {
                if (openImage != value)
                {
                    openImage = value;
                    if (IsExpanded && openImage != null)
                    {
                        SetImage(openImage);
                    }
                }
            }
        }

        public Image ClosedImage
        {
            get
            {
                return closedImage;
            }
            set
            {
                if (closedImage != value)
                {
                    closedImage = value;
                    if (!IsExpanded && closedImage != null)
                    {
                        SetImage(closedImage);
                    }
                }
            }
        }

        private new Image Image
        {
            get
            {
                return base.Image;
            }
            set
            {
                base.Image = value;
            }
        }

        protected void UpdateIcon()
        {
            if (Nodes.Count == 0)
            {
                Image = closedImage;
            }
            else if (IsExpanded)
            {
                Image = openImage;
            }
            else
            {
                Image = closedImage;
            }
        }

        protected internal override void Expanding()
        {
            base.Expanding();
            if (openImage != null)
            {
                Image = openImage;
            }
        }

        protected internal override void Collapsing()
        {
            base.Collapsing();
            if (closedImage != null)
            {
                Image = closedImage;
            }
        }

        public AbstractCustomFolderNode(IProjectManager projectManager)
            : base(projectManager)
        {
        }
    }
}
